<?php
/**
 *
 * @Author nikm $
 *
 * @Date 2012-04-14 $
 */

if(!defined('FROM_INDEX')) exit('Invalid request');

require ROOT_PATH.'module/admin/master.mod.php';

class moduleObj extends masterObj
{
	function __construct($request)
	{
		parent::__construct($request);
				
		$this->excute();
	}
	
	private function excute()
	{
		ob_start();
		
		switch($this->act)
		{
			case 'set_auth':
				$this->setaddAuthStatus();
				break;
			default:
				$this->main();
				break;
		}
		
		$body = ob_get_clean();
		
		$this->showBody($body);
	}
	
	private function main()
	{
		$page = $this->request['offset'] + 1;
		
		$name = isset($this->request['name']) ? $this->request['name'] : '';
		
		$type_list = array('business'=>'bu', 'hostel'=>'ho', 'scenic'=>'sc', 'shop'=>'sh');
		$type = isset($this->request['type']) ? $this->request['type'] : '';
		$this->request['type'] = isset($type_list[$type]) ? $type_list[$type] : '';

		$order = (isset($this->request['order']) && $this->request['order'] == 'asc') ? 'desc' : 'asc';
		$order_name = (isset($this->request['order']) && $this->request['order'] == 'asc') ? '倒序' : '正序';
		
		$is_auth = isset($this->request['is_auth']) ? $this->request['is_auth'] : '';
		
		$query_link = "manage.php?m=credit_list";
		$query_link .= $name ? '&name='.urlencode($name) : '';
		$query_link .= $type ? '&type='.urlencode($type) : '';
		$query_link .= $order ? '&order='.$order : '';
		$query_link .= $is_auth ? '&is_auth='.$is_auth : '';
		$query_link = $query_link;
		
		$result = get_credit_list($this->request);

		$total_record = $result['count'];
		$page_html = page($total_record, $this->request['limit'], $page, $query_link, '10 20 50 100 200 500');
		
		$list = $result['result'];
		
		include template('admin/credit_list');
	}
	
	private function setaddAuthStatus()
	{
		//DBFunction::getInstance()->setDebug();
		
		$this->request['id'] = isset($this->request['id']) ? (int)$this->request['id'] : '';
		$this->request['status'] = (isset($this->request['status']) && $this->request['status'] == 'add') ? '1' : '0';
		
		$type = isset($this->request['type']) ? $this->request['type'] : 'business';
		$order = (isset($this->request['order']) && $this->request['order'] == 'asc') ? 'desc' : 'asc';
		
		$redirect = 'manage.php?m=credit_list&type='.$type.'&order='.$order;
		
		if(!$this->request['id'])
		{
			$this->messager("请指定ID", $redirect);
		}
		
		$result = set_auth_status($this->request);
		
		if($result)
		{
			$this->messager("修改成功", $redirect);
		}
		else
		{
			$this->messager("修改失败", $redirect);
		}
	}
}